﻿// See https://aka.ms/new-console-template for more information

using Console_Cala;

Console.WriteLine("欢迎使用计算器程序，输入exit退出。");
while (true)
{
    try
    {
        Console.Write("输入第一个数字（或exit)：");
        string? input1 = Console.ReadLine();
        if (input1?.ToLower() == "exit") break;
        Console.Write("输入操作符号：");
        string? op = Console.ReadLine();
        Console.Write("输入第二个数字：");
        string? intput2 = Console.ReadLine();

        if (!double.TryParse(input1, out double num1) || !double.TryParse(intput2, out double num2))
        {
            Console.WriteLine("数字输入无效，请输入有效的数字");
            continue;
        }

        double result = op switch
        {
            "-" => num1 - num2,
            "+" => num1 + num2,
            "*" => num1 * num2,
            "/" => num1 / num2,
            _ => throw new InvalidOperationException()
        };

        Console.WriteLine($"{num1} + {num2} = {result}");
    }
    catch (DivideByZeroException e)
    {
        Console.WriteLine($"错误：{e.Message}");
    }
    catch (Exception e)
    {
        Console.WriteLine($"错误：{e.Message}");
        throw;
    }

}